package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Ap0stoL2
 * Date: 2023-07-22
 * Time: 9:47
 */
class MyRunnable implements Runnable{

    @Override
    public void run() {

        while(true){
            System.out.println("hello thread");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {

        //把实现Runnable接口的对象当成参数传给Thread的构造函数
        MyRunnable myRunnable = new MyRunnable();
        Thread t =new Thread(myRunnable);
        t.start();
        while(true)
        {
            System.out.println("i am main");
            Thread.sleep(5000);
        }
    }

}
